/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// TGUI - Texus's Graphical User Interface
// Copyright (C) 2012 Bruno Van de Velde (VDV_B@hotmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
//    you must not claim that you wrote the original software.
//    If you use this software in a product, an acknowledgment
//    in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
//    and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


#ifndef _TGUI_INFO_FILE_PARSER_INCLUDED_
#define _TGUI_INFO_FILE_PARSER_INCLUDED_

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

namespace tgui
{
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    struct TGUI_API InfoFileParser : public sf::NonCopyable
    {
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Destructor. Closes the file if still open.
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        ~InfoFileParser();


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Open a given file. If a file is already open then it will be closed first.
        //
        // return:  true when the file was opened
        //          false when it couldn't be opened
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        bool openFile(const std::string filename);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Reads the next line of the file, removes spaces and tabs, removes comments and then searches for an equal mark.
        // The word before the equal mark is stored in property, everything after the equal mark is stored in Value.
        // If the line is empty or if no equal mark was found the function will read the next line.
        //
        // return:  true when a property was found
        //          false when the end of the file was reached
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        bool readProperty(std::string& property, std::string& value);


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Close the file that was opened by the OpenFile function.
        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        void closeFile();


        /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    private:

        std::ifstream m_File;
    };

    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

#endif //_TGUI_INFO_FILE_PARSER_INCLUDED_

